package kr.co.dayve.site.management.dao;

import kr.co.dayve.site.domain.Category;
import kr.co.dayve.site.domain.Item;
import kr.co.dayve.site.domain.Member;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

public class MemberDaoImpl extends SqlMapClientDaoSupport implements MemberDao {
    public List getMemberListBySearchword(Member member){

        /**
         * Null 에러 방지용 공백 전환
         */
        if(member.getId() == null){
            member.setId("");
        }

        if(member.getNick_name() == null){
            member.setNick_name("");
        }

        if(member.getEmail() == null){
            member.setEmail("");
        }

        return getSqlMapClientTemplate().queryForList("MEMBER.getMemberListBySearchword", member, member.getCurrentPage() * member.getPageSize(), member.getPageSize());
    }

    public String getTotalMemberCountBySearchword(Member member){
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getTotalMemberCountBySearchword", member);        
    }


	public Member getMemberById(String id) {
        return (Member)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberById", id);
    }

    public Member getMemberByEmail(String id){
        return (Member)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberByEmail", id);
    }

    public Member getMemberByIdEmail(Member member){
        return (Member)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberByIdEmail", member);
    }


    public String updateMemberById(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.updateMemberById", member));
    }

    public String adminUpdateMemberById(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.adminUpdateMemberById", member));
    }

    public String updateMemberPasswordById(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.updateMemberPasswordById", member));
    }

	public String getMemberExistById(String id) {
		return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberExistById", id);
	}

    public String getMemberExistByEmail(String email){
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberExistByEmail", email);
    }

    public String getMemberExistByIdEmail(Member member){
        return (String)getSqlMapClientTemplate().queryForObject("MEMBER.getMemberExistByIdEmail", member);
    }

	
	public String logIn(Member member) {
		return (String)getSqlMapClientTemplate().queryForObject("MEMBER.logIn", member);
	}

    public String deleteMemberById(String id){
        return Integer.toString(getSqlMapClientTemplate().delete("MEMBER.deleteMemberById", id));
    }

    public String insertMember(Member member){
        return Integer.toString(getSqlMapClientTemplate().update("MEMBER.insertMember", member));
    }

    public List getCategoryMemberListByCategoryName(Category category){
        return getSqlMapClientTemplate().queryForList("MEMBER.getCategoryMemberListByCategoryName", category);
    }

    public List getItemMemberListByItemName(Item item){
        return getSqlMapClientTemplate().queryForList("MEMBER.getItemMemberListByItemName", item);
    }
}
